package com.goods.controller.business;

import com.goods.business.service.ConsumerService;
import com.goods.common.model.business.Consumer;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ConsumerVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "业务模块-物资去处相关接口")
@RestController
@RequestMapping("/business/consumer")
public class ConsumerController {

  @Autowired
  private ConsumerService consumerService;

  @ApiOperation(value = "物资去向列表",notes = "物资去向列表分页展示")
  @GetMapping("/findConsumerList")
  public ResponseBean findConsumerList(@RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
                                       @RequestParam(value = "pageSize")Integer pageSize,
                                       ConsumerVO consumerVO){
    PageVO<ConsumerVO> consumerVOPageVO = consumerService.findConsumerList(pageNum,pageSize,consumerVO);
    return ResponseBean.success(consumerVOPageVO);
  }

  @ApiOperation(value = "添加物资去处")
  @PostMapping("/add")
  public ResponseBean add(@RequestBody @Validated ConsumerVO consumerVO){
    consumerService.add(consumerVO);
    return ResponseBean.success();
  }

  @ApiOperation(value = "编辑物资去处页面")
  @GetMapping("/edit/{id}")
  public ResponseBean edit(@PathVariable Long id){
    ConsumerVO consumerVO = consumerService.edit(id);
    return ResponseBean.success(consumerVO);
  }

  @ApiOperation(value = "提交修改物资去向")
  @PutMapping("/update/{id}")
  public ResponseBean update(@PathVariable Long id,@RequestBody @Validated ConsumerVO consumerVO){
    consumerService.update(id,consumerVO);
    return ResponseBean.success();
  }

  @ApiOperation(value = "删除物资去向信息")
  @DeleteMapping("/delete/{id}")
  public ResponseBean delete(@PathVariable Long id){
    consumerService.delete(id);
    return ResponseBean.success();
  }
}
